<template>
  <!-- 成本调整-新增 -->
  <div class="e-form">
       <BillTop title="成本调整新增" @cancel="cancel"></BillTop>
    <div class="tabs">
      <div class="tabs-title">基本信息</div>
      <div style="width: 100%" class="form">
        <el-form :model="formData" label-width="150px"  :rules="rules"
          ref="formData"
          class="demo-ruleForm">
          <el-row>
            <el-col :span="12">
               <el-form-item label="所属机构：">
                 {{formData.orgName}}
              </el-form-item>
            </el-col>
            <el-col :span="12">
                 <el-form-item label="调整日期：" prop="inventoryDate">
                <el-date-picker
                  v-model="formData.inventoryDate"
                  type="date"
                  placeholder="选择日期"
                  :clearable="false"
                >
                </el-date-picker>
              </el-form-item>

            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
                 <el-form-item label="录入人：">
                     {{formData.inventoryPersonnelName}}
              </el-form-item>

            </el-col>
            <el-col :span="12">
                 <el-form-item label="状态：">
              {{ '草稿' }}
            </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-form-item label="备注：">
              <el-input
                type="textarea"
                :rows="2"
                placeholder="请输入内容"
                v-model="formData.remarks"
              >
              </el-input>
            </el-form-item>
          </el-row>
        </el-form>
      </div>
    </div>
    <div class="buttons">
       <span class="tip"
        ><span style="color: red; margin-right: 0">*</span>为必填项</span
      >
      <el-button type="primary" style="background: #2e61d7" @click="save('formData')"
        >保存</el-button
      >
      <el-button @click="cancel()">关闭</el-button>
    </div>
  </div>
</template>

<script>
import '@/utils/jquery.scrollTo.min'
import Api from '@/api/materials/consumptionInventory.js'

export default {
    data () {
        return {
            //表单数据
            formData: {
                'billId': '',
                'billNo': '',
                'businessType': null,
                'contractId': '',
                'contractName': '',
                'founderId': '',
                'founderName': '',
                'gmtCreate': '',
                'gmtModified': '',
                'inventoryDate': '',
                'inventoryPersonnelId': '',
                'inventoryPersonnelName': '',
                'isRed': null,
                'nullifyCreated': '',
                'nullifyCreator': '',
                'nullifyCreatorId': '',
                'nullifyDescription': '',
                'nullifyReason': '',
                'orgId': '',
                'orgName': '',
                'redBillId': '',
                'redBillNo': '',
                'redBillState': '',
                'remarks': '',
                'sourceId': '',
                'sourceNumber': '',
                'state': '0',
                'subcontractorId': '',
                'subcontractorName': '',
                'workId': ''
            },
            orgId: '', //机构id
            orgName: '', //机构名称
            isSkip: false, //是否跳转
            options: [
                {
                    value: 1,
                    key: '分包合同',
                },
                {
                    value: 4,
                    key: '事实合同',
                },

            ],
            //验证
            rules: {
                businessType: [
                    {  required: true, message: '请选择业务类型', trigger: 'change' }
                ],
                inventoryDate: [
                    {  required: true, message: '请选择盘点日期', trigger: 'change' }
                ],

            },
            redFormData: null,

        }
    },
    watch: {
        'formData.redBillState' () {
            if (this.formData.redBillState == '3') {
                this.redBillStateStyle.backgroundColor = '#FF2300'
            } else if (
                this.formData.redBillState == '0' ||
                this.formData.redBillState == '1'
            ) {
                this.redBillStateStyle.backgroundColor = '#FFA40D'
            } else if (this.formData.redBillState == '2') {
                this.redBillStateStyle.backgroundColor = 'rgb(153,153,153)'
            }
        }
    },
    computed: {
        // 红单状态
        redBillStateFun () {
            let redState = ''
            switch (this.formData.redBillState) {
            case '0':
                redState = '冲销中'
                break
            case '1':
                redState = '冲销中'
                break
            case '2':
                redState = '已冲销'
                break
            case '3':
                redState = '红单'
                break
            }
            return redState
        }
    },
    components: {},
    created () {
        try {
            let data = JSON.parse(localStorage.getItem('vuex'))
            this.orgId = data.userInfo.orgInfo.orgId
            this.formData.orgName = data.userInfo.orgInfo.orgName
            this.formData.inventoryPersonnelName = localStorage.getItem('userName')
            this.formData.inventoryPersonnelId = localStorage.getItem('userId')

        } catch (error) {
            alert(error.message)
        }
    },
    mounted () {},
    beforeDestroy () {},
    methods: {

        //保存
        save (formName) {
            this.$refs[formName].validate(valid => {
                if (valid) {
                    if (this.isRedSingle) {
                        this.redFormData.remarks = this.formData.remarks
                    }
                    Api.AddConsumptionInventory(this.formData).then(res => {
                        this.clientPop('suc', '保存成功,是否继续', ()=>{
                            this.$router.replace({
                                path: '/TheCostOfAdjustmentEdit',
                                query: {
                                    billid: res,
                                    name: 'receivingMaterials'
                                }
                            })
                        }, this.cancel)
                    })
                } else {
                    return false
                }
            })

        },
        //取消按钮
        cancel () {
            this.$router.replace('/TheCostOfAdjustment')
        },

    },
}
</script>

<style lang="scss" scoped>
.buttons {
  left: 0;
}
.e-form {
  margin-bottom: 80px;
  padding: 0 20px;
  .tabs-title::before {
    content: "";
    height: 22px;
    width: 8px;
    border-radius: 40px;
    background-color: #2e61d7;
    display: block;
    position: absolute;
    left: 20px;
    margin-right: 20px;
  }
}

.e-table {
  background: #fff;
}

.el-tab-pane {
  margin-left: -10px;
}
</style>
